Build Your Own API

Build your own API allows users to build an API based on their individual needs.

Building API 

Here's the basic workflow:

  1. Build a table that translates your recommendation idea into an algorithm.
    • Who: technical team (SQL experience highly recommended)
    • Where: Build Query Editor
  2. Create an API and publish it.
    • Who: technical team/administrators
    • Where: Build dashboard
  3. Call the API (a URL for each API is provided when you publish it).
    • Who: site developers
    • Where: your website

Building a Table in the Query Editor

The first step in creating an API is to assemble the data you need into a table in Build.

The query editor gives you access to your site's clickstream data, as well as any other data you've brought in through Build. The query editor uses Cloudera Impala to give you SQL access to the Build data.

If you know SQL, you'll do just fine with Impala, but if you need to brush up, the Impala documentation will help. 

Tips:

  • Create your table in the work database.

  • APIs always accept one key value and return multiple sets of values.

  • The table you build controls how much information you want the API to return. If you want the API to return no more than 5 sets of results for each key, you set that limit when you build the table. 

  • API Table Structure

  • Custom APIs accept key values and return sets of values for that key. The table that you build will have columns for the key and each of the values to return. In each row, a key is associated to a set of values. 

Example

If your API receives category IDs and returns information (product IDs, image URLs, and descriptions) for the three most popular products in that category, the table you build can look like this:

categoryID productID url description rank
100 4321 mystore.com/4321.png Hula Hoop 1
100 9876 mystore.com/9876.png Super Pogo Stick 2
100 7654 mystore.com/7654.png Crash O'Matic 3
101 2345 mystore.com/2345.png Blue Storage Ottoman 1
101 8901 mystore.com/8901.png Glass Coffee Table 2
101 3456 mystore.com/3456.png Folding Chair 3

The categoryID column will be used as the API's key. Because, we want the API to return only 3 sets of values, each categoryID gets 3 rows.

Creating APIs

  1. On the API tab, click Create.

  2. Give your API a name. This name will appear in the Build dashboard only.

  3. On the From Table tab, select the table that you built.

  4. In the left table, select the Key, the input for the API.

  5. In the table on the right the Values from your table that the API will return.

  6. Click Publish. Your API appears in the list. If you click the API name, you see the Data Model tab, which includes the URL where you call the API.